package com.itheima.dao.store;

import com.itheima.domain.store.Company;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

/**
 * 企业Dao
 */
public interface CompanyDao {
    /**
     * 查询所有公司信息
     * @return
     * @throws Exception
     */
    @Select("select * from ST_COMPANY")
    @Results(id = "companyResults",value = {
            @Result(column = "id",property = "id",jdbcType = JdbcType.VARCHAR),
            @Result(column = "name",property = "name",jdbcType = JdbcType.VARCHAR),
            @Result(column = "expiration_date",property = "expirationDate",jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "address",property = "address",jdbcType = JdbcType.VARCHAR),
            @Result(column = "license_id",property = "licenseId",jdbcType = JdbcType.VARCHAR),
            @Result(column = "representative",property = "representative",jdbcType = JdbcType.VARCHAR),
            @Result(column = "phone",property = "phone",jdbcType = JdbcType.VARCHAR),
            @Result(column = "company_size",property = "companySize",jdbcType = JdbcType.VARCHAR),
            @Result(column = "industry",property = "industry",jdbcType = JdbcType.VARCHAR),
            @Result(column = "remarks",property = "remarks",jdbcType = JdbcType.VARCHAR),
            @Result(column = "state",property = "state",jdbcType = JdbcType.INTEGER),
            @Result(column = "city",property = "city",jdbcType = JdbcType.VARCHAR)
    })
    List<Company> findAll()throws Exception;


    /**
     * 根据ID查询公司信息
     * @param id
     * @return
     * @throws Exception
     */
    @Select("select * from ST_COMPANY where id = #{id}")
    @ResultMap("companyResults")
    Company findById(String id)throws Exception;

    /**
     * 根据ID修改企业信息
     * @param company
     * @return
     * @throws Exception
     */
    @Update("UPDATE `st_company` SET  `name` = #{name}, `expiration_date` = #{expirationDate}, `address` = #{address}, `license_id` = #{licenseId}, `representative` = #{representative}, `phone` = #{phone}, `company_size` = #{companySize}, `industry` = #{industry}, `remarks` = #{remarks}, `state` = #{state}, `city` = #{city} WHERE `id` = #{id}")
    int update(Company company)throws Exception;

    /**
     * 新增公司
     * @param company
     * @return
     * @throws Exception
     */
    @Insert("INSERT INTO `heima_mm`.`st_company` (`id`,`name`,`expiration_date`,`address`,`license_id`,`representative`,`phone`,`company_size`,`industry`,`remarks`,`state`,`city`) VALUES(#{id},#{name},#{expirationDate},#{address},#{licenseId},#{representative},#{phone},#{companySize},#{industry},#{remarks},#{state},#{city})")
    int save(Company company)throws Exception;

    /**
     * 根据ID删除
     * @param id
     * @return
     * @throws Exception
     */
    @Delete("DELETE FROM st_company where id = #{id}")
    int delete(String id)throws Exception;


}
